<%--
  Created by IntelliJ IDEA.
  User: dj
  Date: 2018-08-10
  Time: 9:59
  To change this template use File | Settings | File Templates.
  var ucode="${sysStaffEntity.ucode}";
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>

    <%@ include file="/common/baseMeta.jsp" %>
    <title>感染信息列表</title>
    <script type="text/javascript">

        var uid = "${sysStaffEntity.uid}";//唯一标识
        var lname = "${sysStaffEntity.lname}"; //登录工号
        $(function () {
            $("#l_datagrid").height(findDimensions_height() - 100);
            $("#HzList_datagrid").height(findDimensions_height() - 100);
            initHzListGrid();
            LoadHzListGrid();
            //初始化查询参数
            $.getJSON("/commapiV2", {p_dm: "Sys_Dictionary_Item_Get", dic_name: "感染数据状态"}, function (data) {
                if (data.success) {
                    $("#grzt").empty();
                    var option = "";
                    $(data.Table).each(function (index, row) {
                        option += "<option value='" + row.code + "'>" + row.name + "</option>";
                    });
                    $("#grzt").append(option);
                }
            }, true);
            $.getJSON("/commapiV2", {p_dm: "Sys_Dictionary_Item_Get", dic_name: "感染分类"}, function (data) {
                if (data.success) {
                    $("#grfl").empty();
                    var option = "";
                    option += "<option value=''></option>";
                    $(data.Table).each(function (index, row) {
                        option += "<option value='" + row.code + "'>" + row.name + "</option>";
                    });
                    $("#grfl").append(option);
                }
            }, true);


            $.getJSON("/commapiV2", {p_dm: "sys_ks_Getzy", userid: lname}, function (data) {
                if (data.success) {
                    $('#ks').combobox({
                        data: data.Table,
                        valueField: 'code',
                        textField: 'name'
                    });
                    $('#ks1').combobox({
                        data: data.Table,
                        valueField: 'code',
                        textField: 'name'
                    });
                }
            }, true);

            //获取用户角色
            $.getJSON("/commapiV2", {p_dm: "Sys_User_Roles_Get", userid: lname}, function (data) {
                if (data.success) {
                    if (data.Table[0]["role_name"] == "管理员组" || data.Table[0]["role_name"] == "院感科组") {
                        $('#sh').show();
                    }
                    else {
                        $('#sh').hide();
                    }
                }
            }, true);
            //初始化选项卡
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                e.target; // 当前切换的dom
                e.relatedTarget; // 先前切换的dom
                if ($(this).attr('id') == 'a1') {
                    $('#tabx2').hide();
                    $('#tabx1').show();
                }
                if ($(this).attr('id') == 'a2') {
                    $('#tabx1').hide();
                    $('#tabx2').show();
                    //初始化表头
                    initGrInfoGrid();
                    LoadGrInfoGrid();
                }
            });
        });
        function LoadGrInfoGrid() {
            var postdata = {
                p_dm: "Thz_Grinfo_Get",
                zyh: $("#zyh").val(),
                sdate: $("#stratdate").val() == "" ? '1987-01-01' : $("#stratdate").val(),
                edate: $("#enddate").val() == "" ? '2090-03-01' : $("#enddate").val(),
                zt: $("#grzt").val() == null ? "未处理" : $("#grzt").val(),
                grfl: $("#grfl").val(),
                KsInfo: $('#ks1').combobox('getValue') + '|' + $('#ks1').combobox('getText'),
                userid: lname
            };
            //从API获取数据，并绑定
            $.getJSON("/commapiV2", postdata, function (data) {
                if (data.success) {
                    var griddata = {};
                    griddata.rows = data.Table;
                    griddata.total = data.totalcount;
                    $('#l_datagrid').datagrid('loadData', griddata);
                }
            });
        }
        function initGrInfoGrid() {
            $('#l_datagrid').datagrid({
                rownumbers: true,//显示行号
                singleSelect: true,//只显示一行
                pagination: true,//启用分页
                fitColumns: true,
                sortable: true, //启用排序列
                collapsible: true,
                idField: 'id',
                pageSize: 50,
                pageList: [50, 100, 150],
                columns: [
                    [
                        {field: 'zt', title: '数据状态', width: '90px', align: 'center'},
                        {field: 'name', title: '感染科室', width: '120px', align: 'center'},
                        {
                            field: 'zyh', title: '住院号', width: '90px', align: 'center',
                            formatter: function (value, row, index) {
                                return '<a style="color:blue" href="/HzinfoDisplay/Hzinfo_sxt?blh=' + row.blh + '&zyh=' + row.zyh + '" target="view_frame">' + row.zyh + '</a>';
                            }
                        },
                        {field: 'zycs', title: '住院次数', width: '55px', align: 'center'},
                        {field: 'hzxm', title: '患者姓名', width: '90px', align: 'center'},
                        {field: 'xb', title: '性别', width: '45px', align: 'center'},
                        {field: 'grsj', title: '感染时间', width: '120px', align: 'center'},
                        {field: 'grmc', title: '感染部位', width: '120px', align: 'center'},
                        {field: 'grfl', title: '感染分类', width: '120px', align: 'center'},
                        {field: 'zgys', title: '主管医生', width: '90px', align: 'center'},
                        {field: 'ssmc', title: '手术名称', width: '120px', align: 'center'},
                        {field: 'WXYS', title: '侵害性操作', width: '120px', align: 'center'},
                        {field: 'YGYS', title: '易感因素', width: '120px', align: 'center'},
                        {field: 'bhyy', title: '驳回原因', width: '220px', align: 'center'},
                        {field: 'grid', title: '感染id', hidden: true},
                        {field: 'blh', title: '病例号', hidden: true},
                        {field: 'id', title: 'id', hidden: true}
                    ]
                ]
            }).datagrid('clientPaging');
        }

        function AddGrinfo() {
            var row = $('#HzList_datagrid').datagrid('getSelected');
            if (row == null) {
                alert("请选中行");
                return;
            }
            var url = "GrinfoEdite?blh=" + row.blh + "&zyh=" + row.zyh + "&PageMode=Add";
            layer.open({
                type: 2,
                title: '感染上报',
                skin: 'layui-layer-demo', //样式类名
                shadeClose: true, //开启遮罩关闭
                shade: [0.3, '#000000'],
                maxmin: true, //开启最大化最小化按钮
                area: ['1100px', '95%'],
                content: url,
                btn: ['确定', '取消'],
                yes: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象，执行iframe页的方法：
                    iframeWin.SaveData();//调用子页面的方法，得到子页面返回的ids 
                    loadList();
                }
            });
        }
        function SHGrinfo() {
            var row = $('#l_datagrid').datagrid('getSelected');
            if (row == null) {
                alert("请选中行");
                return;
            }
            var url = "GrSh?id=" + row.id;
            layer.open({
                type: 2,
                title: '数据修改',
                skin: 'layui-layer-demo', //样式类名
                shadeClose: true, //开启遮罩关闭
                shade: [0.3, '#000000'],
                maxmin: true, //开启最大化最小化按钮
                area: ['1100px', '450px'],
                content: url,
                btn: ['确定', '取消'],
                yes: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象，执行iframe页的方法：
                    iframeWin.SaveData();//调用子页面的方法，得到子页面返回的ids 
                    loadList();
                }
            });
        }
        function EditeGrinfo() {
            var row = $('#l_datagrid').datagrid('getSelected');
            if (row == null) {
                alert("请选中行");
                return;
            }
            var url = "GrinfoEdite?blh=" + row.blh + "&zyh=" + row.zyh + "&PageMode=Edite&id=" + row.id;
            if (row.zt == '已审核') {
                alert("数据已审核不能修改！");
                return;
            }
            layer.open({
                type: 2,
                title: '数据修改',
                skin: 'layui-layer-demo', //样式类名
                shadeClose: true, //开启遮罩关闭
                shade: [0.3, '#000000'],
                maxmin: true, //开启最大化最小化按钮
                area: ['1100px', '95%'],
                content: url,
                btn: ['确定', '取消'],
                yes: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象，执行iframe页的方法：
                    iframeWin.SaveData();//调用子页面的方法，得到子页面返回的ids 
                    loadList();
                }
            });
        }


        function initHzListGrid() {
            $('#HzList_datagrid').datagrid({
                fit: false, //自动适屏功能
                rownumbers: true,//显示行号
                singleSelect: true,//只显示一行
                pagination: true,//启用分页
                remoteSort: false,
                clientPaging: false,
                fitColumns: true,
                sortable: true, //启用排序列
                collapsible: true,
                idField: 'blh',
                pageSize: 50,
                pageList: [50, 100, 150],
                columns: [
                    [
                        {field: 'blh', title: '病例号', hidden: true},
                        {field: 'zgyscode', title: '主管医生代码', hidden: true},
                        {field: 'ryrq', title: '入院日期', hidden: true},
                        {
                            field: 'zyh', title: '住院号', width: '90px', align: 'center',
                            formatter: function (value, row, index) {
                                return '<a style="color:blue" href="/HzinfoDisplay/Hzinfo_sxt?blh=' + row.blh + '&zyh=' + row.zyh + '" target="view_frame">' + row.zyh + '</a>';
                            }
                        },
                        {field: 'zycs', title: '住院次数', width: '55px', align: 'center'},
                        {field: 'hzxm', title: '患者姓名', width: '90px', align: 'center'},
                        {field: 'xb', title: '性别', width: '45px', align: 'center'},
                        {field: 'hznl', title: '年龄', width: '45px', align: 'center'},
                        {field: 'rksj', title: '入科时间', width: '130px', align: 'center'},
                        {field: 'cwh', title: '床位号', width: '90px', align: 'center'},
                        {field: 'zgys', title: '主管医生', width: '120px', align: 'center'},
                        {field: 'ryzd', title: '入院诊断', width: '120px', align: 'center'},
                        {field: 'szks', title: '所在科室', width: '120px', align: 'center'},
                        {field: 'grcs', title: '感染次数', width: '120px', align: 'center'},
                        {field: 'zt', title: '感染状态', width: '120px', align: 'center'},
                    ]
                ],
                rowStyler: function (index, row) {
                    if (row.zt == '确诊') {
                        return 'background-color:pink;color:blue;font-weight:bold;';
                    }
                },
                onDblClickRow: function (index, row) {
                    parent.toggle();
                    parent.InChat(row.szks + '@' + row.zgys, '@' + row.hzxm + "(" + row.zyh + ")", row.zgyscode);
                }
            }).datagrid('clientPaging');
        }
        function LoadHzListGrid() {
            if ($('#PationType').combobox('getValue') == "出院患者" && $('#zyh1').textbox('getValue') == "") {
                alert('请输入住院号');
                return;
            }
            var postdata = {
                p_dm: "Thz_jbxx_GetKshzinfo",
                szks: $('#ks').combobox('getValue'),
                zyh: $('#zyh1').val(),
                hzxm: $('#hzxm').val(),
                userid: lname,
                PationType: $('#PationType').combobox('getValue')
            };
            //从API获取数据，并绑定
            $.getJSON("/commapiV2", postdata, function (data) {
                if (data.success) {
                    var griddata = {};
                    griddata.rows = data.Table;
                    griddata.total = data.totalcount;
                    $('#HzList_datagrid').datagrid('loadData', griddata);
                }
            });
        }
        function DelGrinfo() {
            var row = $('#l_datagrid').datagrid('getSelected');
            if (confirm('您确定要删除吗？')) {
                $.getJSON("/commapiV2", {
                    p_dm: "Thz_Grinfo_UpdateZT",
                    ID: row.id,
                    zt: '已删除'
                }, function (data) {
                    if (data.success) {
                        loadList();
                    }
                }, true);
            }
        }
        function loadList() {
            LoadGrInfoGrid();
        }
    </script>
</head>
<body>
<div style="margin:0 5px; overflow: hidden;">
    <ul class="nav nav-tabs" role="tablist" id="mytab" style="font-size: 12px;">
        <li class="active"><a href="#r_datagrid_tab" data-toggle="tab" id="a1">在院患者</a></li>
        <li><a href="#r_datagrid_mban_tab" data-toggle="tab" id="a2">感染信息</a></li>
    </ul>
    <div style="width:100%;float:left;display:inline-block;padding-top:10px;" id="tabx1">
        <div class="navheader form-inline" style="height:40px;margin-bottom: 0px;">
            <div class=" form-group">
                <label for="ZYNumber" style="padding:5px 10px 0 20px;">状态</label>
                <select id="PationType" class="easyui-combobox" style="height: 25px; width: 160px;">
                    <option value='出院患者'>出院患者</option>
                    <option value='在院患者' selected="selected">在院患者</option>
                </select>
                <label for="ZYNumber" style="padding:5px 10px 0 20px;">科室</label>
                <select id="ks" class="easyui-combobox" style="height: 25px; width: 160px;">
                </select>
                <label for="ZYNumber" style="padding:5px 10px 0 20px;">住院号</label>
                <input class="easyui-textbox" style="width:100px;height:25px" name="zyh1" id="zyh1"
                       prompt="住院号"/>
                <label for="ZYNumber" style="padding:5px 10px 0 20px;">患者姓名</label>
                <input class="easyui-textbox" style="width:100px;height:25px" name="hzxm" id="hzxm"
                       prompt="患者姓名"/>
                <button type="button" class="btn btn-success bi-btn-search" onclick="LoadHzListGrid()">
                    <span class="glyphicon glyphicon glyphicon-search"></span>
                </button>
            </div>
            <div class="btn-group-right">
                <div class="btn-group" role="group">
                    <button type="button" class="btn btn-default bi-btn-width90" onclick="AddGrinfo()">感染上报</button>
                </div>
            </div>
        </div>
        <table id="HzList_datagrid" class="datagrid" style="width:100%;height: 500px"></table>
    </div>
    <div style="width:100%;float:left;display:inline-block;padding-top:10px;" id="tabx2">
        <div class="navheader form-inline" style="height:40px;margin-bottom: 0px;">
            <div class=" form-group">
                <label for="ZYNumber" style="padding:5px 10px 0 20px;">状态</label>
                <select id="grzt"></select>
                <label for="ZYNumber" style="padding:5px 10px 0 20px;">感染分类</label>
                <select id="grfl"></select>
                <label for="CYRQStart" style="padding:5px 10px 0 20px;">感染时间</label>
                <input type="text" class="form-control Wdate" style="width:100px;" name="stratdate" id="stratdate"
                       placeholder=""
                       value="${CYRQStart}"
                       onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })"/>
                <label for="CYRQEnd" style="padding:5px 10px 0 10px;">至</label>
                <input type="text" class="form-control Wdate" style="width:100px;" name="enddate" id="enddate"
                       placeholder=""
                       value="${CYRQEnd}"
                       onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })"/>
                <label for="ZYNumber" style="padding:5px 10px 0 20px;">住院号</label>
                <input type="text" class="form-control" style="width:100px;" name="zyh" id="zyh"
                       placeholder="住院号"/>
                <label for="ZYNumber" style="padding:5px 10px 0 20px;">科室</label>
                <select id="ks1" class="easyui-combobox" style="height: 25px; width: 160px;">
                </select>
                <button type="button" class="btn btn-success bi-btn-search" onclick="LoadGrInfoGrid()">
                    <span class="glyphicon glyphicon glyphicon-search"></span>
                </button>
                <div class="btn-group-right">
                    <div class="btn-group" role="group">
                        <button id="sh" type="button" class="btn btn-default bi-btn-width90" onclick="SHGrinfo()">审核
                        </button>
                        <button type="button" class="btn btn-default bi-btn-width90" onclick="EditeGrinfo()">编辑</button>
                        <button type="button" class="btn btn-default bi-btn-width90" onclick="DelGrinfo()">删除</button>
                    </div>
                </div>
            </div>
        </div>
        <div style="width:100%;float:left;display:inline-block;padding-top:10px;">
            <table id="l_datagrid" class="datagrid" style="width:100%"></table>
        </div>
    </div>
</div>
</body>
</html>
